package com.sylli.oeuf.server.service;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.sylli.oeuf.server.db.DatabaseProviderBundle;
import com.sylli.oeuf.server.exception.BasedException;
import com.sylli.oeuf.server.game.logic.Clazz;
import com.sylli.oeuf.server.game.logic.LevelLogic;
import com.sylli.oeuf.server.game.logic.Leveling;
import com.sylli.oeuf.server.game.logic.Clazz.ClazzId;
import com.sylli.oeuf.server.object.transferable.CharacterGeneralInfoTO;
import com.sylli.oeuf.server.object.transferable.MonsterTO;
import com.sylli.oeuf.server.object.transferable.StatTO;
import com.sylli.oeuf.server.object.transferable.WrappedCharacterInfoTO;


/**
 * Item getter service. (Other service action based on item id)
 */
public class ObjectService extends BasedService {
	// provides getters of various type.
	
	private static Leveling logic = new LevelLogic();
	
	private static Logger log = LoggerFactory.getLogger( "service.object" );
	
	public static DatabaseProviderBundle providers = DatabaseProviderBundle.getInstance();
	
	public MonsterTO getMonster(int monsterId) throws BasedException {
		MonsterTO m = providers.monster.get("monster_id = " + monsterId);
		return m;
	}
	
	public void writeCharacterInfo( WrappedCharacterInfoTO pack ) throws BasedException {
		// unpack.
		CharacterGeneralInfoTO gen = pack.getGeneralInfo();
		ClazzId clazzId = Clazz.getClazzFromId(gen.getClazzId());
		StatTO stat = gen.getStat();
		gen.setMaxHp(logic.getMaxHpFromStat(stat, clazzId));
		gen.setMaxMp(logic.getMaxMpFromStat(stat, clazzId));
		
		providers.charGenInfo.update(pack.getGeneralInfo());
		providers.charPostData.update(pack.getPostData());
	}
}
